home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / v cisle / tclock / tclocklight-040702-3.exe / source / player / dialog.c next >
C/C++ Source or Header  |  2004-04-01  |  5KB  |  198 lines

  1. /*-------------------------------------------------------------
  2.   dialog.c : Player setting dialog
  3.   (C) Kazuto Sato 1997-2003
  4.   For the license, please read readme.txt.
  5.   
  6.   Written by Kazubon, Nanashi-san
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "tcplayer.h"
  10.  
  11. /* Globals */
  12.  
  13. void OnShowDialog(HWND hwnd);
  14.  
  15. HWND g_hDlg = NULL;
  16.  
  17. /* Statics */
  18.  
  19. BOOL CALLBACK DlgProcPlayer(HWND, UINT, WPARAM, LPARAM);
  20. static void OnInit(HWND hDlg);
  21. static void OnOK(HWND hDlg);
  22. static void OnCancel(HWND hDlg);
  23. static void OnHelp(HWND hDlg);
  24. static void OnShowTime(HWND hDlg);
  25. static void OnUserStr(HWND hDlg);
  26.  
  27. static char *m_section = "Player";
  28.  
  29. /*-------------------------------------------------------
  30.   PLAYERM_SHOWDLG message
  31. ---------------------------------------------------------*/
  32. void OnShowDialog(HWND hwnd)
  33. {
  34.     if(g_hDlg && IsWindow(g_hDlg)) ;
  35.     else
  36.         g_hDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_PLAYER),
  37.             NULL, DlgProcPlayer);
  38.     SetForegroundWindow98(g_hDlg);
  39. }
  40.  
  41. /*-------------------------------------------
  42.   dialog procedure
  43. ---------------------------------------------*/
  44. BOOL CALLBACK DlgProcPlayer(HWND hDlg, UINT message,
  45.     WPARAM wParam, LPARAM lParam)
  46. {
  47.     switch(message)
  48.     {
  49.         case WM_INITDIALOG:
  50.             OnInit(hDlg);
  51.             return TRUE;
  52.         case WM_COMMAND:
  53.         {
  54.             int id; //, code;
  55.             id = LOWORD(wParam); // code = HIWORD(wParam);
  56.             switch(id)
  57.             {
  58.                 case IDC_SHOWTIME:
  59.                     OnShowTime(hDlg);
  60.                     break;
  61.                 case IDC_SHOWWHOLE:
  62.                 case IDC_SHOWADD:
  63.                 case IDC_SHOWUSTR:
  64.                     OnUserStr(hDlg);
  65.                     break;
  66.                 case IDOK:
  67.                     OnOK(hDlg);
  68.                     break;
  69.                 case IDCANCEL:
  70.                     OnCancel(hDlg);
  71.                     break;
  72.                 case IDC_PLAYERHELP:
  73.                     OnHelp(hDlg);
  74.                     break;
  75.             }
  76.             return TRUE;
  77.         }
  78.     }
  79.     return FALSE;
  80. }
  81.  
  82. /*-------------------------------------------
  83.   initialize main dialog
  84. ---------------------------------------------*/
  85. void OnInit(HWND hDlg)
  86. {
  87.     HICON hIcon;
  88.     
  89.     // common/tclang.c
  90.     SetDialogLanguage(hDlg, "Player", g_hfontDialog);
  91.     
  92.     hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_TCLOCK));
  93.     SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
  94.     
  95.     // common/dialog.c
  96.     SetMyDialgPos(hDlg, 32, 32);
  97.     
  98.     CheckDlgButton(hDlg, IDC_SHOWTIME,
  99.         GetMyRegLong(m_section, "Disp", FALSE));
  100.     CheckRadioButton(hDlg, IDC_SHOWWHOLE, IDC_SHOWUSTR,
  101.         IDC_SHOWWHOLE + GetMyRegLong(m_section, "DispType", 1));
  102.     SetDlgItemInt(hDlg, IDC_SHOWUSTRNUM,
  103.         GetMyRegLong(m_section, "UserStr", 0), FALSE);
  104.     
  105.     OnShowTime(hDlg);
  106. }
  107.  
  108. /*-------------------------------------------
  109.   "OK" button
  110. ---------------------------------------------*/
  111. void OnOK(HWND hDlg)
  112. {
  113.     int i;
  114.     
  115.     SetMyRegLong(m_section, "Disp",
  116.         IsDlgButtonChecked(hDlg, IDC_SHOWTIME));
  117.     for(i = 0; i < 3; i++)
  118.     {
  119.         if(IsDlgButtonChecked(hDlg, IDC_SHOWWHOLE+i))
  120.         {
  121.             SetMyRegLong(m_section, "DispType", i);
  122.             break;
  123.         }
  124.     }
  125.     SetMyRegLong(m_section, "UserStr", 
  126.         GetDlgItemInt(hDlg, IDC_SHOWUSTRNUM, NULL, FALSE));
  127.     
  128.     if(IsPlayerPlaying())
  129.         InitPlayer(g_hwndPlayer);
  130.     else
  131.         PostMessage(g_hwndPlayer, WM_CLOSE, 0, 0);
  132.     DestroyWindow(hDlg);
  133.     g_hDlg = FALSE;
  134. }
  135.  
  136. /*-------------------------------------------
  137.   "Cancel" button
  138. ---------------------------------------------*/
  139. void OnCancel(HWND hDlg)
  140. {
  141.     if(!IsPlayerPlaying())
  142.         PostMessage(g_hwndPlayer, WM_CLOSE, 0, 0);
  143.     DestroyWindow(hDlg);
  144.     g_hDlg = FALSE;
  145. }
  146.  
  147. /*-------------------------------------------
  148.   "Help" button
  149. ---------------------------------------------*/
  150. void OnHelp(HWND hDlg)
  151. {
  152.     char helpurl[MAX_PATH], title[MAX_PATH];
  153.     
  154.     if(!g_langfile[0]) return;
  155.     
  156.     GetMyRegStr(NULL, "HelpURL", helpurl, MAX_PATH, "");
  157.     if(helpurl[0] == 0)
  158.     {
  159.         if(GetPrivateProfileString("Main", "HelpURL", "", helpurl,
  160.             MAX_PATH, g_langfile) == 0) return;
  161.     }
  162.     
  163.     if(GetPrivateProfileString("Player", "HelpURL", "", title,
  164.         MAX_PATH, g_langfile) == 0) return;
  165.     
  166.     if(strlen(helpurl) > 0 && helpurl[ strlen(helpurl) - 1 ] != '/')
  167.         del_title(helpurl);
  168.     add_title(helpurl, title);
  169.     
  170.     ShellExecute(hDlg, NULL, helpurl, NULL, "", SW_SHOW);
  171. }
  172.  
  173. /*------------------------------------------------
  174.   "Show elasped time" is checked
  175. --------------------------------------------------*/
  176. void OnShowTime(HWND hDlg)
  177. {
  178.     BOOL b;
  179.     int i;
  180.     
  181.     b = IsDlgButtonChecked(hDlg, IDC_SHOWTIME);
  182.     for(i = IDC_SHOWWHOLE; i <= IDC_SHOWUSTRNUM; i++)
  183.         EnableDlgItem(hDlg, i, b);
  184.     
  185.     OnUserStr(hDlg);
  186. }
  187.  
  188. /*------------------------------------------------
  189.   "User string" is checked
  190. --------------------------------------------------*/
  191. void OnUserStr(HWND hDlg)
  192. {
  193.     EnableDlgItem(hDlg, IDC_SHOWUSTRNUM,
  194.         IsDlgButtonChecked(hDlg, IDC_SHOWTIME) &&
  195.         IsDlgButtonChecked(hDlg, IDC_SHOWUSTR));
  196. }
  197.  
  198.